package com.iyunsir.mem.controller;

import com.iyunsir.common.vo.Result;
import com.iyunsir.mem.entity.Mem;
import com.iyunsir.mem.service.MemService;
import com.iyunsir.mem.vo.MemQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/mem")
public class MemController {
    @Autowired
    private MemService memService;
    @GetMapping("")
    public String toMemListUI(){
        return "member/memList";
    }
    @ResponseBody
    @GetMapping("list")
    public Result<Object> getMemList(MemQuery param){
        List<Mem> list = memService.getMemList(param);
        Long count = memService.countMemList(param);
        return Result.success(list,count);
    }
    @PostMapping("")
    @ResponseBody
    public Result<Object> addMem(Mem mem){
        memService.addMem(mem);
        return Result.success("新增会员成功");

    }
    @GetMapping("/add/ui")
    public String toAddUI(){

        return "member/memAdd";
    }

    @DeleteMapping("/{ids}")
    @ResponseBody
    public Result<Object> deleteEmpByIds(@PathVariable("ids") String ids){
        memService.deleteMemByIds(ids);
        return Result.success("删除会员成功！");
    }
    @GetMapping("/{id}")
    public String getMemById(@PathVariable("id") Integer id,Model model){
        Mem mem = memService.getMemByid(id);
        model.addAttribute("mem",mem);
        return "member/memEdit";
    }
    @PutMapping("")
    @ResponseBody
    public Result<Object> updateMem(Mem mem){
        memService.updateMem(mem);
        return Result.success("会员信息修改成功!");

    }

}
